package com.todo.message.application.service.impl;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.common.common.enums.BizErrorCodeEnum;
import com.todo.message.iface.vo.SendRequest;
import com.todo.message.iface.vo.SendResponse;
import com.todo.component.third.party.pipline.ProcessContext;
import com.todo.component.third.party.pipline.ProcessController;
import com.todo.message.application.service.RecallService;
import com.todo.message.application.entity.model.RecallTaskModel;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;


/**
 * 撤回接口
 *
 * @author 3y
 */
@Service
public class RecallServiceImpl implements RecallService {
    @Autowired
    @Qualifier("apiProcessController")
    private ProcessController processController;

    @Override
    public SendResponse recall(SendRequest sendRequest) {

        if (ObjectUtils.isEmpty(sendRequest)) {
            return new SendResponse(BizErrorCodeEnum.PARAM_ERROR.getCode(), BizErrorCodeEnum.PARAM_ERROR.getDesc(), null);
        }
        RecallTaskModel recallTaskModel = RecallTaskModel.builder().messageTemplateId(sendRequest.getMessageTemplateId()).recallMessageId(sendRequest.getRecallMessageIds()).build();
        ProcessContext context = ProcessContext.builder()
                .code(sendRequest.getCode())
                .processModel(recallTaskModel)
                .needBreak(false)
                .response(BizResponse.success())
                .build();

        ProcessContext process = processController.process(context);
        return new SendResponse(process.getResponse().getCode(), process.getResponse().getMessage(), null);
    }
}
